Java 9 with JShell by Gaston C. Hillar

Java 9 with JShell by Gaston C. Hillar

Author:Gaston C. Hillar [Hillar, Gaston C.]
Language: eng
Format: epub, azw3
Publisher: Packt Publishing
Published: 2017-03-28T22:00:00+00:00


Note

JShell ignores the final modifier, and therefore, a class declared with the final modifier will allow subclasses in JShell.

Creating methods that work with instances of different subclasses

After we declare all the new classes, we will create the following two methods that receive a VirtualAnimal instance as an argument, that is, a VirtualAnimal instance or an instance of any subclass of VirtualAnimal. Each method calls a different instance method defined in the VirtualAnimal class: printAverageNumberOfBabies and printAsciiArg. The code file for the sample is included in the java_9_oop_chapter_07_01 folder, in the example07_02.java file.

void printBabies(VirtualAnimal animal) { animal.printAverageNumberOfBabies(); } void printAsciiArt(VirtualAnimal animal) { animal.printAsciiArt(); }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.